<template>
  <ContentWrap>
    <!-- 搜索工作栏 -->
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="职位状态" prop="jobStatus">
        <el-select v-model="queryParams.jobStatus" placeholder="已发布" clearable class="!w-240px">
          <el-option
            v-for="dict in getIntDictOptions(DICT_TYPE.JOB_STATUS)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
        <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
        <el-button
          type="primary"
          plain
          @click="openForm('create')"
          v-hasPermi="['dbit:job-info:create']"
        >
          <Icon icon="ep:plus" class="mr-5px" /> 新增
        </el-button>
        <!-- <el-button
          type="success"
          plain
          @click="handleExport"
          :loading="exportLoading"
          v-hasPermi="['dbit:job-info:export']"
        >
          <Icon icon="ep:download" class="mr-5px" /> 导出
        </el-button> -->
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <div v-for="item in list" :key="item.jobId" style="margin-bottom: 5px;">
      <el-card>
        <div class="job-card">
          <div class="left flex-item">
            <span class="job-name">{{ item.jobName }}</span>
            <div class="job-type">
              <dict-tag
                :type="DICT_TYPE.JOB_TYPE"
                :value="item.jobType"
                style="margin-right: 5px"
              />
              <span v-for="city in item.jobCity" :key="city" style="margin-right: 5px">
                {{ city }}
              </span>
            </div>
          </div>
          <div v-if="item.jobDeliveryNum!==0" class="center flex-item">
            <span class="number">{{ item.jobDeliveryNum }}</span>
            <span class="text">投递数</span>
          </div>
          <div v-else class="center flex-item">
            <span class="text">暂无投递</span>
          </div>
          <div class="right flex-item">
            <el-button
              plain
              type="primary"
              @click="openForm('update', item.jobId)"
              v-hasPermi="['dbit:job-info:update']"
            >
              编辑
            </el-button>
            <el-button
              link
              type="normal"
              @click="openForm1(item.jobId)"
            >
              查看
            </el-button>
            <el-button
              link
              type="danger"
              @click="handleDelete(item.jobId)"
              v-hasPermi="['dbit:job-info:delete']"
            >
              删除
            </el-button>
          </div>
        </div>
      </el-card>
    </div>
    <!-- 分页 -->
    <Pagination
      :total="total"
      v-model:page="queryParams.pageNo"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </ContentWrap>

  <!-- 表单弹窗：添加/修改 -->
  <JobInfoForm ref="formRef" @success="getList" />
  <JobInfoForm1 ref="formRef1" @success="getList" />
</template>

<script setup lang="ts">
import { getIntDictOptions, DICT_TYPE } from '@/utils/dict'
import download from '@/utils/download'
import { JobInfoApi, JobInfoVO } from '@/api/dbit/jobinfo'
import JobInfoForm from './JobInfoForm.vue'
import JobInfoForm1 from './JobInfoForm1.vue'

/** 企业职位信息 列表 */
defineOptions({ name: 'JobInfo' })

const message = useMessage() // 消息弹窗
const { t } = useI18n() // 国际化

const loading = ref(true) // 列表的加载中
const list = ref<JobInfoVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  jobStatus: undefined
})
const queryFormRef = ref() // 搜索的表单
const exportLoading = ref(false) // 导出的加载中

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await JobInfoApi.getJobInfoPage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}

/** 添加/修改操作 */
const formRef = ref()
const formRef1 = ref()
const openForm = (type: string, id?: number) => {
  formRef.value.open(type, id)
}
const openForm1 = (id?: number) => {
  formRef1.value.open(id)
}

/** 删除按钮操作 */
const handleDelete = async (id: number) => {
  try {
    // 删除的二次确认
    await message.delConfirm()
    // 发起删除
    await JobInfoApi.deleteJobInfo(id)
    message.success(t('common.delSuccess'))
    // 刷新列表
    await getList()
  } catch {}
}

/** 导出按钮操作 */
const handleExport = async () => {
  try {
    // 导出的二次确认
    await message.exportConfirm()
    // 发起导出
    exportLoading.value = true
    const data = await JobInfoApi.exportJobInfo(queryParams)
    download.excel(data, '企业职位信息.xls')
  } catch {
  } finally {
    exportLoading.value = false
  }
}

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>
<style scoped>
.job-card {
  display: flex;
  width: 99%;
  height: 60px;
  padding: 32px 32px 20px;
  margin-bottom: 10px;
  justify-content: space-between;
  overflow: hidden;
}

.job-card .left{
  width: 50%;
}

.job-card .center {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 250%;
}

.job-card .right{
  width: 50%;
}

.job-card .center .text {
  font-size: 14px;
  color: #999;
}

.job-card .center .number {
  margin-bottom: 5px;
  font-size: 18px;
  font-weight: 600;
  color: #333;
}

.job-name {
  font-size: 16px;
  font-weight: 600;
  color: #333;
}

.job-type {
  margin-top: 8px;
  font-size: 14px;
  color: #999;
}
</style>
